package adventure.commands;

import adventure.*;
import player.*;

/**
 *
 * @author Michael Hanns
 *
 */
public class RecordSpeedwalk extends AbstractCommand {

    public RecordSpeedwalk(Adventure a) {
        super(a, new String[]{"SPEEDWALK"});
    }

    @Override
    public String validateAndExecute(Player p, String[] args) {
        if (args.length == 1) {
            return "The correct syntax is:\nSPEEDWALK <RECORD/STOPRECORDING/STATUS/CLEAR/GET>";
        } else {
            return speedwalk(p, Util.consolidateArguments(args));
        }
    }

    private String speedwalk(Player p, String command) {
        if (command.equalsIgnoreCase("RECORD")) {
            if (p.recordingSpeedwalk()) {
                return "You are already recording a speedwalk! Type \"SPEEDWALK CLEAR\" to clear.";
            } else {
                p.recordSpeedwalk(true);
                return "You are now recording a speedwalk. Type \"SPEEDWALK GET\" to view.";
            }
        } else if (command.equalsIgnoreCase("STOPRECORDING")) {
            if (!p.recordingSpeedwalk()) {
                return "You not presently recording a speedwalk! Type \"SPEEDWALK RECORD\" to start recording.";
            } else {
                p.recordSpeedwalk(false);
                return "You are no longer recording a speedwalk. Type \"SPEEDWALK GET\" to view.";
            }
        } else if (command.equalsIgnoreCase("STATUS")) {
            if (p.recordingSpeedwalk()) {
                return "You are recording a speedwalk. Type \"SPEEDWALK GET\" to view.";
            } else {
                return "You are not presently recording a speedwalk. Type \"SPEEDWALK RECORD\" to start recording.";
            }
        } else if (command.equalsIgnoreCase("CLEAR")) {
            p.clearSpeedwalk();
            return "Speedwalk cleared.";
        } else if (command.equalsIgnoreCase("GET")) {
            return "Your current speedwalk is:\n" + p.getSpeedwalk();
        }
        return "The correct syntax is:\nSPEEDWALK <RECORD/STOPRECORDING/STATUS/CLEAR/GET>";
    }
}


